<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Shop_order;
use zgldh\QiniuStorage\QiniuStorage;
class ShopController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    //查询全部订单
    public function index()
    {
        //
        $data=Shop_order::all();
        return json_encode(['code'=>'10001','msg'=>'订单展示','data'=>$data]);
    }

    //删除订单
    public function del(){
        $id=$_GET['id'];
        $one=Shop_order::findOrFail($id);
        $data=$one->delete();
        if($data){
            $data=Shop_order::all();
            return json_encode(['code'=>'10001','msg'=>'订单展示','data'=>$data]);
        }else{
            return json_encode(['code'=>'10002','msg'=>'删除失败']);
        }
    }

    //查询订单详情
    public function info(){
        $id=$_GET['id'];
        $data=Shop_order::findOrFail($id);
        // $data=$da->get()->toArray();
        // var_dump($data);die;
        if($data){
            return json_encode(['code'=>'10001','msg'=>'详情查询','data'=>$data]);
        }
    }
    

    //七牛云
    public function qiniu(){
        $file=$_FILES;
        $res=QiniuStorage::disk('qiniu');
        $file_name=time().$file['file']['name'];
        $upload=$res->put('images_'.$file_name,file_get_contents($file['file']['tmp_name']));
        if($upload){
            $path=$res->downloadUrl('images_'.$file_name);
            echo $path;die;

        }
    }

    //查询待付款
    public function obligation(){
        $data=Shop_order::where('shop_status_num','1')->get()->toArray();
        return json_encode(['code'=>'10001','msg'=>'等待买家付款','data'=>$data]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //

    }
    public function ceshi(){
        echo 123;
    }

}
